package data_structure;

public class leetcode_0082 {
    public ListNode deleteDuplicates(ListNode head) {

        int val=999;
        if(head==null||head.next==null) return head;

        while(head.val==head.next.val){
            val=head.val;
            while(head.val==val){
                head=head.next;
            }
        }
        if(head==null||head.next==null) return null;
        ListNode p=head;
        ListNode q=head;
        p=p.next;
        while(p!=null){
            while(val==p.val){
                q.next=p.next;
                p=p.next;
            }
            if(p.next!=null&&p.val==p.next.val){
                val=p.val;
            }
            else{
                p=p.next;
                q=q.next;
            }
        }
        return head;
    }
}
